package com.atguigu.yygh.hosp.controller.api;/*
 * @author: XueYouPeng
 * @time: 2023/6/12 19:36
 */

import com.atguigu.common.result.Result;
import com.atguigu.yygh.hosp.service.HospitalService;
import com.atguigu.yygh.hosp.service.ScheduleService;
import com.atguigu.yygh.model.hosp.Hospital;
import com.atguigu.yygh.vo.hosp.HospitalQueryVo;
import com.atguigu.yygh.vo.hosp.ScheduleOrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

//挂号网站使用
@RestController
@RequestMapping("/api/hosp/hospital")
public class HospitalApiController {

    @Autowired
    HospitalService hospitalService;

    @Autowired
    ScheduleService scheduleService;

    @GetMapping("getScheduleOrderVo/{scheduleId}")
    public ScheduleOrderVo getScheduleOrderVo(@PathVariable("scheduleId") String scheduleId){
        return scheduleService.getScheduleOrderVo(scheduleId);
    }

    @GetMapping("getBookingScheduleRule/{pageNum}/{pageSize}/{hoscode}/{depcode}")
    public Result getBookingScheduleRule(
            @PathVariable Integer pageNum,@PathVariable Integer pageSize,
            @PathVariable String hoscode,@PathVariable String depcode
    ){
        Map<String,Object> map = scheduleService.getBookingScheduleRule(pageNum,pageSize,hoscode,depcode);
        return Result.ok().data(map);
    }

    /*
     * 首页，查询医院列表 （分页+条件）
     * @author: XueYouPeng
     * @time: 2023/6/12 19:37
     */
    @GetMapping("{page}/{limit}")
    public Result index(
            @PathVariable Integer page,
            @PathVariable Integer limit,
            HospitalQueryVo hospitalQueryVo
    ){
        Page<Hospital> hospitalPage = hospitalService.hospitalList(page, limit, hospitalQueryVo);
        return Result.ok().data("pages",hospitalPage);
    }

    /**
     * 根据输入的关键词模糊查询医院列表
     * @param hosname
     * @return
     */
    @GetMapping("findByName/{hosname}")
    public Result findByName(@PathVariable String hosname){
        List<Hospital> list = hospitalService.findByName(hosname);
        return Result.ok().data("list",list);
    }

    /**
     * 首页点击某个医院，跳转的下一个页面，根据医院编号查询
     * @param hoscode
     * @return
     */
     @GetMapping("/show/{hoscode}")
     public  Result show(@PathVariable String hoscode){
         Hospital hospital = hospitalService.getHospByHoscode(hoscode);
         return Result.ok().data("hospital",hospital).data("bookingRule",hospital.getBookingRule());
     }
}
